package com.xgq.drink.controller;

import com.xgq.drink.entity.MemberLevel;
import com.xgq.drink.entity.R;
import com.xgq.drink.service.IMemberLevelService;
import com.xgq.drink.utils.RUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/memberLevel")
@Tag(name = "会员模块", description = "会员层级相关接口")
public class MemberLevelController {
    @Autowired
    private IMemberLevelService memberLevelService;

    /**
     * 查询所有会员层级
     * @return 会员层级列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询所有会员层级", description = "返回会员层级列表")
    public R getAllMemberLevels() {
        try {
            List<MemberLevel> memberLevels = memberLevelService.getAllMemberLevels();
            return RUtils.success("查询成功", memberLevels);
        } catch (Exception e) {
            return RUtils.fail("查询失败: " + e.getMessage());
        }
    }

    /**
     * 修改会员层级信息
     * @param memberLevel 修改后的会员层级信息
     * @return 操作结果
     */
    @PutMapping("/update")
    @Operation(summary = "修改会员层级信息", description = "根据提供的会员层级信息进行修改")
    public R updateMemberLevel(@RequestBody @Valid MemberLevel memberLevel) {
        try {
            memberLevelService.updateMemberLevel(memberLevel);
            return RUtils.success("会员层级更新成功");
        } catch (Exception e) {
            return RUtils.fail("会员层级更新失败: " + e.getMessage());
        }
    }
}